import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/9 15:14
 * @description 接受一个十六进制的数，输出该数的十进制表示
 */
public class Solution {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()) {
            String s = scanner.nextLine().substring(2);
            int ans = 0, i = 0;
            for (char c : s.toCharArray()) {
                int temp = 0;
                if (c >= 97 && c <= 103) {
                    temp = c - 87;
                } else if (c >= 65 && c <= 71) {
                    temp = c - 55;
                } else {
                    temp = c - 48;
                }
                ans += (int) Math.pow(16, s.length() - i - 1) * temp;
                i++;
            }
            System.out.println(ans);
        }
    }
}
